import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:jetour_line/base_widget/base_image.dart';
import 'package:jetour_line/base_widget/sliver_list_widget.dart';
import 'package:jetour_line/map/base_map_widget.dart';
import 'package:jetour_line/my_colors.dart';
import 'package:jetour_line/utils/extension_int.dart';

import '../../../model/line_detail_model.dart';
import '../../../utils/page_push_utils.dart';
import '../../map_detail_page.dart';

class LineDetailMapWidget extends StatefulWidget {
  final LineDetailModel lineDetailModel;

  LineDetailMapWidget({Key? key, required this.lineDetailModel})
      : super(key: key);
  @override
  State<LineDetailMapWidget> createState() => _LineDetailMapWidgetState();
}

class _LineDetailMapWidgetState extends State<LineDetailMapWidget> {
  List nodes = [];
  @override
  Widget build(BuildContext context) {

    if(nodes.isEmpty){
      int index = 1;
      int len = widget.lineDetailModel.lineData!.length;
      for(int i = 0 ;i<len;i++){
        LineDatum? datum = widget.lineDetailModel.lineData![i];
        List<LineDatumNode?>? node =  datum!.node;
        for(int j = 0;j<node!.length;j++){///不要改key值  跟原生一一对应
          Map<String,dynamic> map = {};
          map['nodeId'] = node[j]?.nodeId;
          map['index'] = index++;
          map['groupIndex'] = i;
          map['childIndex'] = j;
          map['caption'] = node[j]?.caption;
          map['lat'] = node[j]?.lat;
          map['lng'] = node[j]?.lng;
          map['type'] = 'lineDetail';
          nodes.add(map);
        }
      }
    }
    return  SliverListWidget.getSliverContainer(450.px, Container(
      padding: EdgeInsets.only(bottom: 36.px),
      width: double.infinity,
      height: double.infinity,
      color: Colors.white,
      child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        Container(
          width: double.infinity,
          height: 24.px,
          color: MyColors.colorF1F1F1,
        ),
        Padding(padding: EdgeInsets.only(left: 24.px,right: 24.px,bottom: 36.px),child: Container(
          alignment: Alignment.centerLeft,
          height: 88.px,
          child:Text("路线地图",style: TextStyle(fontSize: 32.px,color: MyColors.color1A1A1A,fontWeight: FontWeight.w500),),
        ), ),

        Expanded(
          child: Padding(padding: EdgeInsets.only(left: 24.px,right: 24.px,bottom: 36.px),child: ClipRRect(
            borderRadius: BorderRadius.all(Radius.circular(12.px)),
            child:Stack(alignment: Alignment.center, children: [
              Container(child:  BaseMapWidget(creationParams: nodes,), ),
              GestureDetector(onTap: (){
                PagePushUtils.push(context, MapDetailScreen(markers: nodes));
              },child: ClipRRect(borderRadius: BorderRadius.all(Radius.circular(16.px)), child:  Container(
                width: 188.px,
                height: 114.px,
                color: MyColors.white,
                child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
                  BaseImage(image: 'icon_lsmap',width: 40.px,height: 40.px,),
                  Text("查看地图",style: TextStyle(fontSize: 24.px,color: MyColors.appColor,))
                ],),
              ),))
            ],),
          ),),
        ),



        Container(
          width: double.infinity,
          height: 24.px,
          color: MyColors.colorF1F1F1,
        ),
      ],),
    ));
  }
}
